package cn.edu.hbvtc.qms.persist.hibernate;

import java.util.List;

import cn.edu.hbvtc.qms.domain.Course;
import cn.edu.hbvtc.qms.domain.Major;
import cn.edu.hbvtc.qms.persist.ICourseDao;

public class HibernateCourseDao extends HibernateAbstractDao<Course, Integer>
		implements ICourseDao {

	private static final long serialVersionUID = 1L;

	public HibernateCourseDao() {
		super(Course.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Course> findCoursesOfMajor(int majorId) {
		return this.getHibernateTemplate().find("from Course c where c.major.id = ?", majorId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Course> findCoursesOfType(int id) {
		return this.getHibernateTemplate().find("from Course c where c.courseType = ?", id);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Course findCourseByCourseId(String courseId) {
		List<Course> courseList = this.getHibernateTemplate().find("from Course c where c.courseId= ?", courseId);
		Course course = null;
		if (courseList != null && courseList.size() > 0) {
			course = courseList.get(0);
		}
		return course;
	}
	
}
